package com.rasenhund.android.gsimulator.activity;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.rasenhund.android.gsimulator.R;
import com.rasenhund.android.gsimulator.adapter.MsListAdapter;
import com.rasenhund.android.gsimulator.common.Const;
import com.rasenhund.android.gsimulator.common.Const.CATEGORY;
import com.rasenhund.android.gsimulator.common.Const.KEY;
import com.rasenhund.android.gsimulator.schema.MobileSuit;

/**
 * MS選択画面
 */
public class SelectMsActivity extends BaseActivity {
    @SuppressWarnings("unused")
    private static final String TAG = SelectMsActivity.class.getSimpleName();
    private final SelectMsActivity self = this;

    MsListAdapter mAdapter = null;
    
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.select_ms);

        int iCategoryCd = getIntent().getIntExtra(KEY.KEY_CATEGORY_CD, CATEGORY.BASE);

        ArrayList<MobileSuit> list = Const.getMsList(mArmyCd, iCategoryCd);
        mAdapter = new MsListAdapter(self, list);

        ListView lstMs = (ListView) findViewById(R.id.lstMs);
        lstMs.setOnItemClickListener(lstMs_OnItemClickListener);
        lstMs.setAdapter(mAdapter);

    }

    /********************
     * EventListener
     ********************/

    /**
     * ListItem クリック時のイベントリスナ
     */
    final OnItemClickListener lstMs_OnItemClickListener = new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {

            MobileSuit item = mAdapter.getItem(pos);

            // 機体一覧に選択されたMSをセット
            mLstMachine.set(mMachineNo, item);

            // 編成選択画面に戻る
            Intent intent = new Intent(self, SelectSlotActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);

        }

    };

    /********************
     * Method
     ********************/

}
